package com.yanyeori.framework.security.bo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.yanyeori.framework.core.constant.ChannelEnum;
import com.yanyeori.framework.security.entity.User;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * UserDetail
 *
 * @author chenkuan 2020/11/20
 */
@Getter
@Setter
@NoArgsConstructor
public class UserDetail extends User implements UserDetails {

    //登录ip
    private String loginIp;
    //登录渠道
    private ChannelEnum channel;

    private boolean enabled = true;

    public UserDetail(String username, String password) {
        super(username, password);
    }

    @JsonIgnore
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
//		List<SimpleGrantedAuthority> authorities = new ArrayList<>();
//		authorities.add(new SimpleGrantedAuthority("/auth/login"));
//		return authorities;
        return null;
    }

    @Override
    public String getUsername() {
        return super.getUsername();
    }

    @Override
    public String getPassword() {
        return super.getPassword();
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return enabled;
    }
}
